﻿using Newtonsoft.Json;

namespace OpenPms.Controllers;
/// <summary>
/// 预订单
/// </summary>
[Route("api/[controller]")]
public class ReservationController : PmsControllerBase<ReservationController>
{
    public ReservationController(IServiceProvider serviceProvider) : base(serviceProvider)
    {
    }
    /// <summary>
    /// 查询
    /// </summary>
    /// <param name="reservationId">预订单号，可空</param>
    /// <param name="mobile">联系人手机号，可空</param>
    /// <param name="name"> 联系人姓名或者部分姓名，可空</param>
    /// <returns></returns>
    [HttpGet]
    public Task<List<TReservation>> Query(Guid? reservationId, string? mobile, string? name)
    => OrderService.QueryReservationAsync(HotelId, reservationId, mobile, name);

    /// <summary>
    ///  预订
    /// </summary>
    /// <param name="q"></param>
    /// <returns>预订单号</returns>
    [HttpPost(nameof(Create))]
    public async Task<Guid> Create(TReservation q)
    {
        q.SourceName = configuration.GetSection(Consts.SectionSource).GetValue<string>(q.SouceId.ToString()) ?? "";
        q.HotelId = HotelId;
        return await OrderService.CreateReservationAsync(q);
    }

    /// <summary>
    /// 取消
    /// </summary>
    /// <param name="q">预订单号或者Ota订单号</param>
    /// <returns>主订单号</returns>
    [HttpDelete(nameof(Cancel))]
    public async Task<Guid> Cancel(RequestCancelReservation q)
    {
        q.HotelId = HotelId;
        return await OrderService.CancelReservationAsync(q);
    }

    /// <summary>
    /// 转登记单，并自动排房
    /// </summary>
    /// <param name="reservationId">预订单号</param>
    /// <returns></returns>
    [HttpPost(nameof(Register))]
    public Task<TReservation> Register(Guid reservationId)
    {
        return OrderService.RegisterAsync(HotelId, reservationId);
    }


}

